<template>
  <el-dialog :title="'入账'" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="消费" name="one">
        <el-row>
          <el-col :span="inputPriceFlag ? 7 : 24" style="padding-right: 5px; border-right: 1px solid #ddd;">
            <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
              <el-form-item size="small" label="消费账号">
                <el-select v-model="dataForm.peopleId" placeholder="请选择">
                  <el-option v-for="item in options.peopleOptions" :key="item.name" :label="item.roomNum + '-' + item.name"
                    :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item size="small" label="消费类目" style="margin-bottom: 0px;">
                <el-select v-model="dataForm.consumeId" @change="consumeChange" placeholder="请选择">
                  <el-option v-for="item in dataList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item size="small" :style="dataList.filter(item=>item.isQuick == 1).length == 0 ? '' : 'margin-bottom: 2px;'">
                <el-link style="margin-right: 5px;" v-for="item in dataList.filter(item=>item.isQuick == 1)" :key="item.id"
                  @click="linkClick(item)" type="primary">{{item.name}}</el-link>
              </el-form-item>

              <el-form-item label="消费金额" prop="payPrice">
                <el-input v-model="dataForm.payPrice" :disabled="inputPriceFlag" placeholder="金额"></el-input>
              </el-form-item>

              <el-form-item size="small" label="是否付款">
                <el-radio-group v-model="fukuan" size="mini">
                  <el-radio :label="1">付款</el-radio>
                  <el-radio :label="2">不付款</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item size="small" label="付款方式" v-if="fukuan == 1">
                <el-select v-model="dataForm.nowType" placeholder="请选择">
                  <el-option v-for="item in options.paysTypeOptions" :key="item.name" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="付款金额" v-if="fukuan == 1" prop="payPrice">
                <span>{{ dataForm.payPrice }}</span>
              </el-form-item>

              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
              </el-form-item>
            </el-form>
          </el-col>
          <el-col :span="17" style="padding-left: 6px;" v-if="inputPriceFlag">
            <el-form :inline="true" :model="dataForm">
              <el-form-item>
                <el-select v-model="dataForm.consumeId2" @change="getShopDataList" placeholder="类别" clearable>
                  <el-option v-for="item in consumeEntities" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-input v-model="dataForm.key" placeholder="名称" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-button icon="el-icon-search" circle @click="getShopDataList"></el-button>
              </el-form-item>
            </el-form>
            <el-table :data="shopDataList" v-loading="dataListLoading" style="width: 100%;">
              <el-table-column prop="shopName" header-align="center" align="center" label="名称"></el-table-column>
              <el-table-column prop="salePrice" header-align="center" align="center" label="售价">
                <template slot-scope="scope">
                  <el-input-number size="mini" @change="shopChange" v-model="scope.row.salePrice" :precision="2" :step="1"
                    :min="0"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column prop="count" header-align="center" align="center" label="数量">
                <template slot-scope="scope">
                  <el-input-number size="mini" @change="shopChange(scope.row.count)" v-model="scope.row.count" :step="1"
                    :min="0" :max="scope.row.stockNum"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column prop="stockNum" header-align="center" align="center" label="剩余库存">
                <template slot-scope="scope">
                  {{ scope.row.stockNum - scope.row.count }}
                </template>
              </el-table-column>
            </el-table>
            <el-pagination style="text-align: right;margin-top: 10px;" @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
              :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
          </el-col>
        </el-row>

        <span class="dialog-footer">
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit(2)">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
      <el-tab-pane label="收款" name="first">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
          <el-form-item size="small" label="收款账号">
            <el-select v-model="dataForm.peopleId" placeholder="请选择">
              <el-option v-for="item in options.peopleOptions" :key="item.name" :label="item.roomNum + '-' + item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item size="small" label="收款方式">
            <el-select v-model="dataForm.nowType" placeholder="请选择">
              <el-option v-for="item in options.paysTypeOptions" :key="item.name" :label="item.name" :value="item.id"></el-option>
            </el-select>
            <el-button size="small" class="in_block" v-if="state == 1" @click="state = 2">取消押金</el-button>
            <el-button size="small" class="in_block" v-else @click="state = 1">标记押金</el-button>
          </el-form-item>
          <el-form-item size="small" label="金额" prop="payPrice">
            <el-input style="width: 199px;" v-model="dataForm.payPrice" placeholder="金额"></el-input>
            <el-tag type="danger" v-if="state == 1">押</el-tag>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
        <span class="dialog-footer">
          <el-checkbox v-model="printShouKuanCheck" style="margin-right: 10px;">打印收款单</el-checkbox>
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit(0)">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
      <el-tab-pane label="退款" name="three">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
          <el-form-item size="small" label="退款账号">
            <el-select v-model="dataForm.peopleId" placeholder="请选择">
              <el-option v-for="item in options.peopleOptions" :key="item.name" :label="item.roomNum + '-' + item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item size="small" label="退款方式">
            <el-select v-model="dataForm.nowType" @change="nowTypeChange" placeholder="请选择">
              <el-option v-for="item in options.paysTypeOptions" :key="item.name" :label="item.name" :value="item.id"></el-option>
            </el-select>
            <el-button size="small" class="in_block" v-if="state == 1" @click="state = 2">取消押金</el-button>
            <el-button size="small" class="in_block" v-else @click="state = 1">标记押金</el-button>
          </el-form-item>
          <el-form-item label="可退金额" v-if="refundableAmountVisible">
            <span>{{ refundableAmount }}</span>
          </el-form-item>
          <el-form-item size="small" label="金额" prop="payPrice">
            <el-input style="width: 199px;" v-model="dataForm.payPrice" placeholder="金额"></el-input>
            <el-tag type="danger" v-if="state == 1">押金</el-tag>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
        <span class="dialog-footer">
          <el-checkbox v-model="printTuiKuanCheck" style="margin-right: 10px;">打印退款单</el-checkbox>
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit(5)">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
      <el-tab-pane label="预授权" name="second">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
          <el-form-item size="small" label="入账账号">
            <el-select v-model="dataForm.peopleId" placeholder="请选择">
              <el-option v-for="item in options.peopleOptions" :key="item.name" :label="item.roomNum + '-' + item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item size="small" label="授权方式"><span>银行卡</span></el-form-item>
          <el-form-item label="银行卡号" prop="banksNumber">
            <el-input v-model="dataForm.banksNumber" placeholder="银行卡号"></el-input>
          </el-form-item>
          <el-form-item label="授权号" prop="referenceNumber">
            <el-input v-model="dataForm.referenceNumber" placeholder="授权号"></el-input>
          </el-form-item>
          <el-form-item label="授权金额" prop="payPrice">
            <el-input v-model="dataForm.payPrice" placeholder="金额"></el-input>
          </el-form-item>
          <el-form-item label="有效期" prop="payPrice">
            <el-date-picker v-model="dataForm.termValidity" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
        <span class="dialog-footer">
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit(1)">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
    </el-tabs>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="请扫描二维码" :visible.sync="payVisible"
      width="30%" append-to-body>
      <div v-loading="payLoding" element-loading-text="正在执行支付">
        <div style="  display: flex;
      justify-content: center;
      align-items: center;margin-bottom:10px">
          <img src="../../../../assets/img/barCode.jpg" />
        </div>

        <div style="text-align:center">支持微信或支付宝条码支付</div>
        <div style="text-align:center">请用条码枪进行扫描</div>
        <span>
          <el-input v-model="auth_no" placeholder="请扫描二维码,支持微信支付宝" @keyup.enter.native="authClose" ref="inputFocus"></el-input>
        </span>
      </div>
    </el-dialog>

    <t7 v-show="false" id="t7" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t7"></t7>
    <t8 v-show="false" id="t8" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t8"></t8>
    <t9 v-show="false" id="t9" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t9"></t9>
    <fk7 v-show="false" id="fk7" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="fk7"></fk7>
    <fk8 v-show="false" id="fk8" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="fk8"></fk8>
    <fk9 v-show="false" id="fk9" :note="this.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="fk9"></fk9>
  </el-dialog>
</template>

<script>
  import t7 from '../../../common/printtemplate/shoukuan_58mm';
  import t8 from '../../../common/printtemplate/shoukuan_80mm';
  import t9 from '../../../common/printtemplate/shoukuan_A5';
  import fk7 from '../../../common/printtemplate/fukuan_58mm';
  import fk8 from '../../../common/printtemplate/fukuan_80mm';
  import fk9 from '../../../common/printtemplate/fukuan_A5';
  import moment from 'moment';
  import {
    getLodop
  } from '../../../../utils/lodop';
  export default {
    props: ['note','priceMap', 'currData'],
    data() {
      return {
        infoSet:{
          peopleEntity: {},
          singleEntity: {},
          floorRoomEntity: {},
          roomEntity: {}
        },
        inputPriceFlag: true,
        printTuiKuanCheck: false,
        printShouKuanCheck: false,
        state: 2,
        dataListLoading: false,
        fukuan: 2,
        refundableAmountVisible: false,
        refundableAmount: 0,
        payTypeSign: 0,
        dataList: [],
        refundableAmountList: [],
        shopDataList: [],
        options: {
          paysTypeOptions: [],
          peopleOptions: []
        },
        payLoding: false,
        timer: null,
        dataForm: {
          id: 0,
          key: '',
          sellerId: '',
          consumeId: '',
          consumeId2: '',
          payType: '',
          creatTime: '',
          payPrice: 0,
          banks: '',
          banksNumber: '',
          referenceNumber: '',
          termValidity: '',
          peopleId: '',
          remarks: '',
          nowType: '',
          type: ''
        },
        consumeEntities: [],
        printconfig: {},
        printconfig2: {},
        rowData: {},
        dataRule: {
          sellerId: [{
            required: true,
            message: '商家不能为空',
            trigger: 'blur'
          }]
        },
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        activeName: 'first',
        visible: false,
        info: {},
        payInterfaceConfig: {}, //支付
        payVisible: false,
        auth_no: '',
        countnum: 0
      };
    },
    components: {
      t7,
      t8,
      t9,
      fk7,
      fk8,
      fk9
    },
    methods: {
      linkClick(item) {
        this.dataForm.consumeId = item.id
        this.consumeChange()
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getShopDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getShopDataList();
      },
      //获取所有分类
      getFloorLists() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsume/data'),
          method: 'get',
          params: this.$http.adornParams({

          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            var map = {};
            map["value"] = '-1';
            map["label"] = '全部';
            var children = [];
            map["children"] = children;

            this.floorDataList.push(map);
            // this.floorDataList = data.data;
            this.floorDataList = this.floorDataList.concat(data.data);
          } else {
            this.floorDataList = [];
          }
        });
      },
      loadPrintConfig() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/3`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig = data.tHotelPrintTemplate;
          } else {
            this.$message.error(data.msg);
          }
        });
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/4`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig2 = data.tHotelPrintTemplate;
          } else {
            this.$message.error(data.msg);
          }
        });
      },
      shopChange(counts) {
        //计算价格
        this.countnum = counts;
        var money = 0;
        this.shopDataList.forEach(item => {
          var count = item.count;
          var salePrice = item.salePrice;
          money += count * salePrice;
        });
        this.dataForm.payPrice = money;
      },
      consumeChange() {
        this.dataForm.consumeId2 = '';
        this.shopDataList = []
        //请求旗下分类
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsume/subsetList'),
          method: 'get',
          params: this.$http.adornParams({
            parentId: this.dataForm.consumeId,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.consumeEntities = data.consumeEntities
          }
        });
        this.getShopDataList();
      },
      // 获取数据列表
      getShopDataList() {
        this.dataListLoading = true;
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsumeshop/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: this.pageIndex,
            limit: this.pageSize,
            parentId: this.dataForm.consumeId2 ? this.dataForm.consumeId2 : this.dataForm.consumeId,
            state: 1,
            key: this.dataForm.key
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.shopDataList = data.page.list.map(item => ({
              ...item,
              count: 0
            }));
            this.totalPage = data.page.totalCount;
            if (this.totalPage > 0) {
              this.inputPriceFlag = true;
            } else {
              this.inputPriceFlag = false;
            }
          } else {
            this.shopDataList = [];
          }
          this.dataListLoading = false;
        });
      },
      // 获取数据列表
      getDataList() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsume/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            parentId: 0
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list;
            //默认选中第一个
            this.dataForm.consumeId = this.dataList[0].id
            this.consumeChange();
            console.log(this.dataList);
          } else {
            this.dataList = [];
          }
        });
      },
      init(item) {
        this.visible = true;
        this.info = item;
        this.loadPrintConfig();
        this.getDataList();
        this.getPayTypes();
        this.getPeopls();
        this.$forceUpdate();
        this.$nextTick(() => {
          this.dataForm.peopleId = item.id;
        });
        this.getPayInterface();
        this.getInfo();
        if (this.$cookie.get('printShouKuanCheck') != null) {
          if (this.$cookie.get('printShouKuanCheck') == 1) {
            this.printShouKuanCheck = true
          } else {
            this.printShouKuanCheck = false
          }
        }
        if (this.$cookie.get('printTuiKuanCheck') != null) {
          if (this.$cookie.get('printTuiKuanCheck') == 1) {
            this.printTuiKuanCheck = true
          } else {
            this.printTuiKuanCheck = false
          }
        }
      },
      getInfo() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/pop_single/${this.info.id}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.infoSet.peopleEntity = data.data.peopleEntity;
            if (data.data.peopleEntity.state != 4) {
              this.infoSet.peopleEntity = {
                ...this.infoSet.peopleEntity,
                newArrivalsTime: moment(this.infoSet.peopleEntity.arrivalsTime).format('MM/DD HH:mm'),
                newPredissociationTime: moment(this.infoSet.peopleEntity.predissociationTime).format('MM/DD HH:mm')
              };
              console.log(this.infoSet.peopleEntity);
              this.infoSet.floorRoomEntity = data.data.floorRoomEntity;
              this.infoSet.roomEntity = data.data.roomEntity;
            }
            this.infoSet.singleEntity = data.data.singleEntity;
          }
        });
      },
      //获取支付方式
      getPayTypes() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroompaytype/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            state: 1,
            isDeposit: 1
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.options.paysTypeOptions = data.page.list;
            this.dataForm.nowType = this.options.paysTypeOptions[0].id;
          } else {
            this.options.paysTypeOptions = [];
          }
        });
      },
      //获取入账账号
      getPeopls() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/pop_people/${this.info.singleId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.options.peopleOptions = data.data;
          } else {
            this.options.peopleOptions = [];
          }
        });
      },
      handleClick(tab, res) {

      },
      getPayInterface() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsellerpayinterfaceconfig/myInfo`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.payInterfaceConfig = data.tHotelSellerPayInterfaceConfig
          } else {
            this.$message.error("加载支付配置失败")
          }
        })
      },
      printSK(rowData) {
        this.$refs.t7.setRowData(rowData);
        this.$refs.t8.setRowData(rowData);
        this.$refs.t9.setRowData(rowData);
        this.$nextTick(() => {
          this.rowData = rowData;
          setTimeout(() => {
            LODOP = getLodop();
            if (!LODOP) {
              this.$alert(
                `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
                '安装', {
                  confirmButtonText: '确定',
                  dangerouslyUseHTMLString: true
                }
              );
              return;
            }


            //样式
            var strStyleCSS =
              " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";

            var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + strStyleCSS + '</head>' + ' <style> ' +
              'div{border:0!important}' + '</style>';
            var body = '';
            if (this.printconfig.specs === '58mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t7.$refs.t7.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 580, 3000, ''); //设定纸张大小
            }
            if (this.printconfig.specs === '80mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t8.$refs.t8.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 800, 2500, ''); //设定纸张大小
            }
            if (this.printconfig.specs === 'A5') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t9.$refs.t9.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 2100, 2000, ''); //设定纸张大小
            }
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, 0, 1000, 2000, body); //增加超文本项

            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
            // LODOP.PRINT_INIT('订单') //打印初始化
            LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
            LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
            LODOP.SET_PRINT_COPIES(this.printconfig.printSum);

            LODOP.SET_LICENSES("", "4B44F795076C8F14211A5ED0A5339305DAB", "23580B189D96F33252722697A57AC00506B",
              "");

            if (this.printconfig.preview) {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              }
            } else {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PREVIEW();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              }
            }
          }, 100)

        });
      },
      printTuiK(rowData) {
        this.$refs.fk7.setRowData(rowData);
        this.$refs.fk8.setRowData(rowData);
        this.$refs.fk9.setRowData(rowData);
        this.$nextTick(() => {
          setTimeout(() => {
            this.rowData = rowData;


            LODOP = getLodop();
            if (!LODOP) {
              this.$alert(
                `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
                '安装', {
                  confirmButtonText: '确定',
                  dangerouslyUseHTMLString: true
                }
              );
              return;
            }


            //样式
            var strStyleCSS =
              " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";

            var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + strStyleCSS + '</head>' + ' <style> ' +
              'div{border:0!important}' + '</style>';
            var body = '';
            if (this.printconfig2.specs === '58mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig2.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.fk7.$refs.t7.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 580, 3000, ''); //设定纸张大小
            }
            if (this.printconfig2.specs === '80mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig2.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.fk8.$refs.t8.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 800, 2500, ''); //设定纸张大小
            }
            if (this.printconfig2.specs === 'A5') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig2.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.fk9.$refs.t9.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 2100, 2000, ''); //设定纸张大小
            }
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, 0, 1000, 2000, body); //增加超文本项

            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
            // LODOP.PRINT_INIT('订单') //打印初始化
            LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
            LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
            LODOP.SET_PRINT_COPIES(this.printconfig2.printSum); //设置打印次数

            LODOP.SET_LICENSES("", "4B44F795076C8F14211A5ED0A5339305DAB", "23580B189D96F33252722697A57AC00506B",
              "");

            if (this.printconfig2.preview) {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig2.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig2.defaultPrint);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              }
            } else {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig2.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig2.defaultPrint);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              }
            }

          }, 100)
        });
      },
      //支付方式变更触发
      nowTypeChange(val) {
        this.refundableAmountVisible = false;
        console.log(val)
        console.log("当前配置：", this.payInterfaceConfig)
        if (this.payInterfaceConfig.switchConfig == 1 && this.activeName == 'three') {
          if (this.payInterfaceConfig.payTypeId === val) {
            //查询可退预授权金额
            this.refundableAmount = 0;
            this.$http({
              url: this.$http.adornUrl(
                `/hotel/thotelfloorroomcheckinpeople/view_ysq_money/${this.dataForm.peopleId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({
              data
            }) => {
              this.refundableAmountVisible = true;
              if (data && data.code === 0) {
                this.refundableAmount = data.data.money
                if (data.money > 0) {
                  this.refundableAmountList = data.data.resultEntities
                }
              } else {
                this.$message.error(data.msg)
              }
            })
            return
          }
        }
      },
      // 表单提交
      dataFormSubmit(type) {
        if (type == 2) {
          if (this.dataForm.consumeId == '-1') {
            if (this.countnum <= 0) {
              this.$message.error("请选择右边类型");
              return false
            }
          }

        }


        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            if (this.dataForm.payPrice <= 0) {
              this.$message.error(type == 5 ? "退款金额需大于0" : "收款金额需大于0")
              return false
            }
            if (type == 5) {
              if (this.printTuiKuanCheck) {
                this.$cookie.set('printTuiKuanCheck', 1)
              } else {
                this.$cookie.set('printTuiKuanCheck', 2)
              }
            } else if (type == 0) {
              if (this.printShouKuanCheck) {
                this.$cookie.set('printShouKuanCheck', 1)
              } else {
                this.$cookie.set('printShouKuanCheck', 2)
              }
            }

            var flag = false;
            if (type == 5 || type == 0) {
              flag = true;
            }

            console.log("当前配置：", this.payInterfaceConfig)
            if (this.payInterfaceConfig.switchConfig == 1 && flag) {
              if (this.payInterfaceConfig.payTypeId === this.dataForm.nowType) {
                if (type == 5) {
                  if (this.dataForm.payPrice > this.refundableAmount) {
                    this.$message.error("退款金额不可超过已授权可退金额")
                    return
                  } else {
                    //发起退款请求
                    this.$http({
                      url: this.$http.adornUrl(
                        `/hotel/thotelfloorroomcheckinpeople/view_ysq_finish/${this.dataForm.peopleId}`),
                      method: 'get',
                      params: this.$http.adornParams({
                        amount: this.dataForm.payPrice
                      })
                    }).then(({
                      data
                    }) => {
                      this.refundableAmountVisible = true;
                      if (data && data.code === 0) {
                        Object.assign(this.$data, this.$options.data());
                        this.$message({
                          message: this.$t('Common.OperationSuccessful'),
                          type: 'success',
                          duration: 1500,
                          onClose: () => {
                            this.visible = false;
                            this.$emit('refreshDataList');
                          }
                        });
                      } else {
                        this.$message.error(data.msg)
                      }
                    })
                  }
                  return
                } else {
                  this.payVisible = true;
                  this.payTypeSign = type;
                  this.changeFocus();
                  return
                }
              }
            }

            this.$http({
              url: this.$http.adornUrl(
                `/hotel/thotelfloorroomcheckinaccounting/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                payType: type,
                payPrice: this.dataForm.payPrice,
                banks: this.dataForm.banks,
                banksNumber: this.dataForm.banksNumber,
                referenceNumber: this.dataForm.referenceNumber,
                consumeId: this.dataForm.consumeId,
                conids: this.dataForm.consumeIds,
                termValidity: this.dataForm.termValidity,
                peopleId: this.dataForm.peopleId,
                remarks: this.dataForm.remarks,
                nowType: this.dataForm.nowType,
                fukuan: this.fukuan,
                flooroomid: this.info.floorRoomId,
                ruzhuno: this.info.ruzhuNo,
                state: this.state,
                submitType: 1,
                sign: JSON.stringify(this.shopDataList.filter(item => item.count > 0)),
                type: 0
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                if (type == 0) {
                  console.log("test0", this.printShouKuanCheck)
                  if (this.printShouKuanCheck) {
                    this.printSK(data.accounting)
                  }
                }
                if (type == 5) {
                  console.log("test5", this.printTuiKuanCheck)
                  if (this.printTuiKuanCheck) {
                    this.printTuiK(data.accounting)
                  }
                }
                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    Object.assign(this.$data, this.$options.data());
                    this.rowData = data.accounting
                    this.visible = false;
                  }
                });

                this.$nextTick(() => {
                  this.$emit('refreshDataList');
                });
              } else {
                this.$message.error(data.msg)
              }
            });
          }
        });
      },
      authClose() {
        // this.payVisible = false;
        this.payLoding = true;
        //扫码支付请求数据
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/preAuthBar'),
          method: 'post',
          data: this.$http.adornData({
            'type': 2, //正式
            'auth_no': this.auth_no, //授权码，客户的付款码
            'total_fee': this.dataForm.payPrice * 100, //金额，单位分
            'order_body': '测试', //订单描述
            'attach': '测试', //附加数据,原样返回
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            console.log(data)
            this.payVisible = false
            //保存入账信息
            this.auth_no = "";
            this.payLoding = false;
            var terminalTrace = data.data.terminalTrace
            this.authSubForm(terminalTrace);
          } else if (data.code == 3) {
            //循环查询订单，直至成功或失败
            this.timer = setInterval(() => {
              this.queryOrder(data.data);
            }, 1500);
          } else {
            this.payLoding = false;
            this.auth_no = "";
            this.payVisible = false
            this.$message.error(data.msg);
          }
        })
      },
      queryOrder(data) {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/commonQuery'),
          method: 'post',
          data: this.$http.adornData({
            'pay_type': data.payType,
            'terminal_trace': data.terminalTrace,
            'terminal_time': data.terminalTime,
            'out_trade_no': data.outTradeNo,
          })
        }).then(({
          data
        }) => {
          console.log(data)
          if (data && data.code === 0) {
            clearInterval(this.timer)
            this.payLoding = false;
            console.log(data)
            this.payVisible = false
            this.auth_no = "";
            //保存入账信息
            var terminalTrace = data.data.terminalTrace
            this.authSubForm(terminalTrace);
          } else if (data.code === 3) {

          } else {
            clearInterval(this.timer)
            this.payLoding = false;
            this.payVisible = false
            this.auth_no = "";
            this.$message.error(data.msg);
          }
        })
      },
      authSubForm(terminalTrace) {
        this.$http({
          url: this.$http.adornUrl(
            `/hotel/thotelfloorroomcheckinaccounting/${!this.dataForm.id ? 'save' : 'update'}`),
          method: 'post',
          data: this.$http.adornData({
            collectionNo: terminalTrace,
            payType: this.payTypeSign,
            payPrice: this.dataForm.payPrice,
            banks: this.dataForm.banks,
            banksNumber: this.dataForm.banksNumber,
            referenceNumber: this.dataForm.referenceNumber,
            consumeId: this.dataForm.consumeId,
            termValidity: this.dataForm.termValidity,
            peopleId: this.dataForm.peopleId,
            remarks: this.dataForm.remarks,
            nowType: this.dataForm.nowType,
            state: this.state,
            fukuan: this.fukuan,
            submitType: 1,
            sign: JSON.stringify(this.shopDataList.filter(item => item.count > 0)),
            type: 0
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            Object.assign(this.$data, this.$options.data());
            this.$nextTick(() => {
              this.$emit('refreshDataList');
            });
            if (type == 0) {
              if (this.printShouKuanCheck) {
                this.printSK(data.accounting)
              }
            }
            if (type == 5) {
              if (this.printTuiKuanCheck) {
                this.printTuiK(data.accounting)
              }
            }
            this.$message({
              message: this.$t('Common.OperationSuccessful'),
              type: 'success',
              duration: 1500,
              onClose: () => {

              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      },
      changeFocus() {
        this.$nextTick(() => {
          this.$refs.inputFocus.focus();
        })
      }
    }
  };
</script>

<style lang="scss" scoped>
  .el-radio-group>.el-radio {
    margin-right: 0;
  }

  .el-radio+.el-radio {
    margin-left: 10px;
  }

  @media (max-width: 1400px) {
    .el-dialog__wrapper /deep/ .el-dialog {
      width: 72%;
    }
  }
</style>
